package sandau.self_improvement_wall.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import sandau.self_improvement_wall.security.IpRateLimitInterceptor;

/**
 * @author LuanZheng
 * @date 2025/5/14 12:06
 */
// 注册拦截器
@Configuration
public class WebConfig implements WebMvcConfigurer {
    private final IpRateLimitInterceptor ipRateLimitInterceptor;

    public WebConfig(IpRateLimitInterceptor ipRateLimitInterceptor) {
        this.ipRateLimitInterceptor = ipRateLimitInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(ipRateLimitInterceptor)
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/public/**");
    }
}